package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InvAccount;
import com.ruoyi.system.service.IInvAccountService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 投资帐号Controller
 * 
 * @author ruoyi
 * @date 2022-01-12
 */
@Controller
@RequestMapping("/book/account")
public class InvAccountController extends BaseController
{
    private String prefix = "book/account";

    @Autowired
    private IInvAccountService invAccountService;

    @RequiresPermissions("book:account:view")
    @GetMapping()
    public String account()
    {
        return prefix + "/account";
    }

    /**
     * 查询投资帐号列表
     */
    @RequiresPermissions("book:account:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InvAccount invAccount)
    {
        startPage();
        List<InvAccount> list = invAccountService.selectInvAccountList(invAccount);
        return getDataTable(list);
    }

    /**
     * 导出投资帐号列表
     */
    @RequiresPermissions("book:account:export")
    @Log(title = "投资帐号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InvAccount invAccount)
    {
        List<InvAccount> list = invAccountService.selectInvAccountList(invAccount);
        ExcelUtil<InvAccount> util = new ExcelUtil<InvAccount>(InvAccount.class);
        return util.exportExcel(list, "投资帐号数据");
    }

    /**
     * 新增投资帐号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存投资帐号
     */
    @RequiresPermissions("book:account:add")
    @Log(title = "投资帐号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InvAccount invAccount)
    {
        return toAjax(invAccountService.insertInvAccount(invAccount));
    }

    /**
     * 修改投资帐号
     */
    @RequiresPermissions("book:account:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        InvAccount invAccount = invAccountService.selectInvAccountById(id);
        mmap.put("invAccount", invAccount);
        return prefix + "/edit";
    }

    /**
     * 修改保存投资帐号
     */
    @RequiresPermissions("book:account:edit")
    @Log(title = "投资帐号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InvAccount invAccount)
    {
        return toAjax(invAccountService.updateInvAccount(invAccount));
    }

    /**
     * 删除投资帐号
     */
    @RequiresPermissions("book:account:remove")
    @Log(title = "投资帐号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(invAccountService.deleteInvAccountByIds(ids));
    }
}
